﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using UnityEngine;
using WsGameFrame;


public class PathHelper
{

    /// <summary>
    /// streamingAssetsPath
    /// </summary>
    public static string streamingAssetsPath
    {
        get
        {

            string path = "";
            //if (Application.platform == RuntimePlatform.Android)
            //    path = "jar:file://" + Application.dataPath + "!/assets/"; //在Android中实例化WWW不能在路径前面加"file://"
            //else if (Application.platform == RuntimePlatform.IPhonePlayer)
            //    path = Application.dataPath + "/Raw";//在Windows中实例化WWW必须要在路径前面加"file:///"
            //else
            //    path = DataProcess.streamingAssetsPath;
#if UNITY_ANDROID && !UNITY_EDITOR
                 path = "jar:file://" + Application.dataPath + "!/assets";
#elif UNITY_IPHONE && !UNITY_EDITOR
            path ="file://"+ Application.dataPath + "/Raw";
#else
            path = "file:///" + Application.streamingAssetsPath;
#endif

            return path;
        }
    }


}


public class Filer : BaseSinglton<Filer> {

    #region TEXT

    /// <summary>
    /// 读取文件
    /// </summary>
    /// <param name="FilePath"></param>
    /// <returns></returns>
    public string ReadTXTFile(string FilePath)
    {
        if (File.Exists(FilePath))
        {
            StreamReader stream = null;
            stream = File.OpenText(FilePath);
            string content = stream.ReadToEnd();
            stream.Close();
            return content;
        }
        else
        {
            DebugHelper.Warring("文件不存在:" + FilePath);
        }
        return "";
    } 

    /// <summary>
    /// 写入文件
    /// </summary>
    /// <param name="path"></param>
    /// <param name="content"></param>
    public void WriteTXTFile(string path, string content)
    {
        StreamWriter writer;
        writer = File.CreateText(path);
        writer.Write(content);
        writer.Close();
    }

#endregion

#region Xml

    /// <summary>
    /// 读取xml
    /// </summary>
    /// <param name="XmlFilePath"></param>
    public XmlDocument ReadXmlFile(string XmlFilePath)
    {
        XmlDocument xml = new XmlDocument();
        string content = ReadTXTFile(XmlFilePath);
        xml.LoadXml(content);
        return xml;
    }



#endregion


    public void DeleteFile(string path) {
        File.Delete(path);
        DebugHelper.Log("删除存档操作完成!");
    }

}
